package hotel.meituan.oversea.biz.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.constant.CommonBaseConstants;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.MeituanConstants;
import hotel.base.oversea.constant.enums.CommonBaseEnums;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.constant.enums.MtGoodsEnums;
import hotel.base.oversea.constant.enums.MtHotelEnums;
import hotel.base.oversea.constant.quartz.UrlSwitchsEnums;
import hotel.base.oversea.dto.meituan.MtHotelGoodsBreakfastVo;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.meituan.MtHotelOrderJobDealVo;
import hotel.base.oversea.vo.meituan.request.goods.*;
import hotel.base.oversea.vo.meituan.request.order.MtHotelOrderCheckParamVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsStatusVo;
import hotel.base.oversea.vo.meituan.response.order.MtHotelOrderCheckPricesVo;
import hotel.base.oversea.vo.meituan.response.order.MtHotelOrderCheckVo;
import hotel.meituan.oversea.api.entity.MtHotelGoodsUpDownLog;
import hotel.meituan.oversea.api.entity.MtHotelOrderBooking;
import hotel.meituan.oversea.api.entity.MtHotelOrderDelayLog;
import hotel.meituan.oversea.api.entity.MtHotelOrderStateHistory;
import hotel.meituan.oversea.api.vo.SysCommonBase;
import hotel.meituan.oversea.api.vo.down.request.order.MtHotelOrderBookingParamVo;
import hotel.meituan.oversea.api.vo.up.response.order.MtHotelOrderBookingVo;
import hotel.meituan.oversea.biz.config.RedisLock;
import hotel.meituan.oversea.biz.config.service.RedisService;
import hotel.meituan.oversea.biz.mapper.MtHotelGoodsUpDownLogMapper;
import hotel.meituan.oversea.biz.mapper.MtHotelOrderBookingMapper;
import hotel.meituan.oversea.biz.mapper.MtHotelOrderDelayLogMapper;
import hotel.meituan.oversea.biz.service.MtHotelGoodsService;
import hotel.meituan.oversea.biz.service.MtHotelOrderDealService;
import hotel.meituan.oversea.biz.service.MtHotelOrderDealSplitService;
import hotel.meituan.oversea.biz.service.MtHotelOrderService;
import hotel.meituan.oversea.biz.task.MeituanJobBookingUpdateAllSaleGoodsByOneHotelTask;
import hotel.meituan.oversea.biz.task.MeituanJobBookingUpdateGoodsSwInventoryTask;
import hotel.meituan.oversea.biz.task.MeituanNewOrderCheckSimiTask;
import hotel.meituan.oversea.biz.utils.RestTemplateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class MtHotelOrderDealServiceImpl extends BaseServiceImpl implements MtHotelOrderDealService {
    @Autowired
    private MtHotelOrderBookingMapper mtHotelOrderBookingMapper;

    @Autowired
    private RedisLock redisLock;

    @Autowired
    private MtHotelGoodsService mtHotelGoodsService;

    @Autowired
    private MtHotelOrderDelayLogMapper mtHotelOrderDelayLogMapper;

    @Autowired
    private MeituanNewOrderCheckSimiTask meituanNewOrderCheckSimiTask;

    @Autowired
    private MtHotelGoodsUpDownLogMapper mtHotelGoodsUpDownLogMapper;
    @Autowired
    private MeituanJobBookingUpdateGoodsSwInventoryTask meituanJobBookingUpdateGoodsSwInventoryTask;
    @Autowired
    private MeituanJobBookingUpdateAllSaleGoodsByOneHotelTask meituanJobBookingUpdateAllSaleGoodsByOneHotelTask;

    @Autowired
    private MtHotelOrderService mtHotelOrderService;
    @Autowired
    private MtHotelOrderDealSplitService mtHotelOrderDealSplitService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RedisService redisService;

    public static void main(String[] args) {
      /*  BigDecimal a = new BigDecimal("1.06");
        System.out.printf(""+a.multiply(new BigDecimal(100)).intValue());
        BigDecimal s = new BigDecimal(12000);
        Integer m = 10000;
        Integer comparePrice = s.compareTo(new BigDecimal(m));
        if(comparePrice==-1){

        }*/

        String room = "VIP大床房";
        String goods = room.toLowerCase();
        System.out.printf("goods="+goods);

    }
    /**
     * 0.0 定时器新订单下单
     *
     * 四大类，九小类
     *
     * 试单失败： 0 8 code正常，需再次判断价格
     *     库存不足：[JOBMT-CHECK] 订单将延迟处理 :2021-04-29 13:21:04  下单前校验未通过：{"code":6,"desc":"产品库存不足 - 产品id：62291352","priceModels":[],"remainRoomNum":0} 订单总价37128 订购房间数3 订单号=15039583130
     *     内部判断超亏损：[JOBMT-CHECK] 订单将延迟处理 :2021-04-29 12:47:55  单住订单，产品涨价超固定金额：总价10422 房间数1，亏损金额：11014,美团返回{"code":8,"desc":"下单卖价校验失败 - 产品id：608353023, 传入价格为：10422, 实际价格为：23300","priceModels":[{"date":"2021-05-01","dayType":0,"salePrice":23300,"subPrice":1864,"subRatio":800}],"remainRoomNum":999} 订单号=15039382839
     *     暂不可定：[JOBMT-CHECK] 订单将延迟处理 :2021-04-29 10:22:37  下单前校验未通过：{"code":3,"desc":"产品暂不可订 - 产品id：63194977，产品状态为：0","priceModels":[]} 订单总价18356 订购房间数1 订单号=15038611686
     *     命中黑名单(产品失效黑名单)：[JOBMT-CHECK] 订单将延迟处理 :2021-04-28 18:37:43  下单前校验未通过：{"code":2,"desc":"命中黑名单，暂不可售 - poiId：5223809，产品id：6570026，供应商id：12734","priceModels":[]} 订单总价24866 订购房间数1 订单号=15035473404
     *     其他：[JOBMT-CHECK] 订单将延迟处理 :2021-04-26 23:40:01  下单前校验未通过：{"code":5,"desc":"产品查询失败 - 产品id：674063758","priceModels":[]} 订单总价25946 订购房间数1 订单号=15020149938
     *
     * 异步通知失败：
     *     预订失败：[FAILED-NOTICE] 预下单已提交,但美团异步通知预定失败了！订单将延迟处理，请核实 :2021-04-29 12:15:49 {"method":"hotel.order.status.change.callback","data":"{\"mtOrderId\":4845882758375776398,\"distributorOrderId\":\"15039147320001\",\"orderStatus\":22,\"desc\":\"预定失败\"}","accesskey":"a6a02428da2c702188d7a8985fac24f6","signature":"XyJQM4nlyeSk2OL2lDgF4XDp1bQ=","partnerId":12734,"version":"1.0","nonce":1478396260,"timestamp":1619669748} 订单号：15039147320001
     *
     * 预下单失败：
     *      余额不足：[FAILED-BOOKING]下单前校验成功，但美团预下单失败，将延时处理 :2021-04-21 14:13:02：{"code":0,"message":"成功","partnerId":16366,"result":{"mtOrderId":null,"distributorOrderId":null,"code":5,"desc":"账户余额为零，扣款失败，请充值后重试"}} 订单号：14970451912
     *      其他： [FAILED-BOOKING]下单前校验成功，但美团预下单失败，将延时处理 :2021-04-29 00:27:32：{"code":0,"message":"成功","partnerId":12734,"result":{"mtOrderId":3422735875641244899,"distributorOrderId":"15037636697001","code":20,"desc":"预订信息校验失败"}} 订单号：15037636697
     *
     *早餐问题：
     *      早餐匹配不对： [JOBMT-CHECK] 订单将延迟处理 :2021-04-24 17:06:02 新订单校验，早餐信息变化产品早餐从免费变为无早，请核实 订单号=14998974435
     *
     * @return
     */
    @Override
    public Result<Object> jobNewOrderBooking(MtHotelOrderJobDealVo mtHotelOrderJobDealVo) {
        //1、参数
        Integer sysStatus = mtHotelOrderJobDealVo.getSysStatus();
        String swPoolId = mtHotelOrderJobDealVo.getSwPoolId();
        String swOrderId = mtHotelOrderJobDealVo.getSwOrderId();//携程订单id
        String swHotelId = mtHotelOrderJobDealVo.getSwHotelId();//携程酒店id订单将延迟处理
        String swRoomId = mtHotelOrderJobDealVo.getSwRoomId();//携程售卖房型id
        String mtHotelId = mtHotelOrderJobDealVo.getMtHotelId();//美团酒店id
        Integer goodsId = mtHotelOrderJobDealVo.getGoodsId();//美团产品id
        String checkinDate = mtHotelOrderJobDealVo.getCheckinDate();//日期格式 yyyy-MM-dd
        String checkoutDate = mtHotelOrderJobDealVo.getCheckoutDate();
        Integer roomnum = mtHotelOrderJobDealVo.getRoomnum();
        Integer swTotalPrice = mtHotelOrderJobDealVo.getTotalPrice();//分；携程订单金额 totalPrice 单位元转分

        String tjMsg = "";
        try{
            Integer tj = (Integer)redisService.hmGet(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER,Integer.valueOf(mtHotelOrderJobDealVo.getMtHotelId()));//单位分
            if(!ObjectUtils.isEmpty(tj)){
                String start = mtHotelOrderJobDealVo.getCheckinDate();
                String end = mtHotelOrderJobDealVo.getCheckoutDate();
                Long days = DateUtil.dateDiff(start,"day",end,"yyyy-MM-dd");
                tj = BigDecimal.valueOf(tj).multiply(BigDecimal.valueOf(roomnum)).multiply(BigDecimal.valueOf(days)).intValue();//特价和天数和房间数有关
                //Integer updateTotalPrice = BigDecimal.valueOf(mtHotelOrderJobDealVo.getTotalPrice()).subtract(BigDecimal.valueOf(tj)).intValue();//默认为减 与携程前端相反   携程前端价格=（美团市场价-佣金价）x1.18 +50  eg：优惠前价格150 用户优惠支付价格100 接口过来价格是150   上送的美团价格要减去50
                //当前美团端 携程价格已经是调价后上送
                Integer updateTotalPrice = mtHotelOrderJobDealVo.getTotalPrice();
                tjMsg="  0_0为特价酒店{优惠金额="+tj.intValue()+"}";
                log.info("getdltordernotify  美团接收新订单为调价酒店订单订单号={} 调价={},上送美团价格={},房间数={},天数={}",mtHotelOrderJobDealVo.getSwOrderId(),tj,updateTotalPrice,roomnum,days);
            }else{
                log.info("getdltordernotify  美团接收新订单不是调价酒店订单号={},mthotelid={}",mtHotelOrderJobDealVo.getSwOrderId(),mtHotelOrderJobDealVo.getMtHotelId());
            }
        }catch (Exception e){
            log.info("美团新订单特价判断异常：e="+e.getMessage());
            e.printStackTrace();
        }


        Result resultLock = setLockOrderIdKey(swOrderId);
        if(resultLock.getCode()!=CommonConstants.SUCCESS){
            return resultLock;
        }

        if(null !=selectOneBySwOrderIsVail(swOrderId)){
            log.error("jobNewOrderBooking selectOneBySwOrderIsVail 已存在处理中订单，当前提交重复订单号 swOrderId="+swOrderId);
            SendUtils.dingMsgNotLog("[NEW-ORDER-RE]订单号重复return",DateUtil.getCurrTime()+" 查看是否有影响程序执行,订单号："+swOrderId,MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
            return new Result<>("已存在处理中订单，当前提交重复订单号 swOrderId="+swOrderId,CommonConstants.REQUEST_ERROR);
        }

        //2、美团第三方接口-预下单校验
        MtHotelOrderCheckParamVo mtHotelOrderCheckParamVo = new MtHotelOrderCheckParamVo();
        mtHotelOrderCheckParamVo.setHotelId(Long.valueOf(mtHotelId));
        mtHotelOrderCheckParamVo.setGoodsId(goodsId);
        mtHotelOrderCheckParamVo.setCheckinDate(checkinDate);
        mtHotelOrderCheckParamVo.setCheckoutDate(checkoutDate);
        mtHotelOrderCheckParamVo.setRoomNum(roomnum);
        mtHotelOrderCheckParamVo.setTotalPrice(swTotalPrice);
        Result resultCheck = mtHotelOrderService.orderCheckApi(mtHotelOrderCheckParamVo);
        MtHotelOrderCheckVo mtHotelOrderCheckVo = JacksonUtil.objToBean(resultCheck.getData(), MtHotelOrderCheckVo.class);
        String errorMsg = "";
        String breakfastErrMsg = "";
        Boolean isLoss = false;
        String isLossMsg = "";
        boolean isCheckPriceDaysOrderToSplit = false;
        Result errorMsgResult = null;
        if(resultCheck.getCode() == CommonConstants.SUCCESS && null != mtHotelOrderCheckVo) {
            Integer checkCode = mtHotelOrderCheckVo.getCode();
            log.info("check进入");
            if(!isManmadeNotCheckPrice(sysStatus)){
                //判断早餐是否正常
                Result result = checkThisGoodsBreakfast(swOrderId,mtHotelId,String.valueOf(goodsId));
                if(result.getCode()!=CommonConstants.SUCCESS){
                    breakfastErrMsg = (String)result.getMsg();
                }else{
                    //判断价格涨幅亏损
                    errorMsgResult = this.checkPriceUpDown(mtHotelOrderCheckVo,swTotalPrice,roomnum);
                    if(errorMsgResult.getCode()!=CommonConstants.SUCCESS){
                        errorMsg = (String)errorMsgResult.getMsg();
                        if(errorMsgResult.getCode()==99){
                            //连住订单，需预先生成拆单数据，多笔单住订单
                            isCheckPriceDaysOrderToSplit = true;
                        }
                    }else{
                        if(null != errorMsgResult.getMsg() && errorMsgResult.getMsg().toString().contains("isLoss")){
                            isLoss = true;
                            isLossMsg = errorMsgResult.getMsg().toString();
                        }
                    }
                    log.info("进入校验checkCode={},errorMsg={}",checkCode,errorMsg);
                }
                //vesrion qyy 更新库存价格
                Long daysOrder = DateUtil.dateDiff(checkinDate,"day",checkoutDate,"yyyy-MM-dd");
                if(daysOrder==1) {
                    //单住
                    meituanJobBookingUpdateGoodsSwInventoryTask.executeUpdateInventory(swOrderId,swHotelId,swRoomId,checkinDate,checkoutDate,mtHotelOrderCheckVo.getRemainRoomNum(),mtHotelOrderCheckVo,mtHotelId,goodsId);
                }else{
                    //连住，把这几天拆开，单独每天再查询库存
                    meituanJobBookingUpdateAllSaleGoodsByOneHotelTask.executeUpdateAllInventory(mtHotelOrderCheckVo,mtHotelId,"stayDays",mtHotelOrderCheckParamVo,swHotelId,swRoomId);
                }

                if(checkCode == 3 || checkCode == 6){//该酒店所有售卖房型，轮询查询未来一天
                    log.info("进入校验进入meituanJobBookingUpdateAllSaleGoodsByOneHotelTask={}",checkCode);
                    //3 房态不可预订  6 库存不足   当存在酒店某产品下单前校验为， 将当前酒店其他所有产品更新一下
                    meituanJobBookingUpdateAllSaleGoodsByOneHotelTask.executeUpdateAllInventory(mtHotelOrderCheckVo,mtHotelId,null,mtHotelOrderCheckParamVo,swHotelId,swRoomId);
                }
            }else{
                log.info("人工处理40");
            }
        }else{
            //下单前校验接口返回失败，延迟订单，修改携程pool表
            errorMsg = " 下单前校验返回失败="+ JSON.toJSONString(resultCheck);
            //下单前校验失败，保存延时订单日志
            saveDelayLog(swOrderId,MtGoodsEnums.DelayParentStatus.CHECK.getCode(),MtGoodsEnums.DelayParentStatus.CHECK.getMsg(),MtGoodsEnums.DelayStatus.CHECK_OTHER.getCode(),MtGoodsEnums.DelayStatus.CHECK_OTHER.getMsg(),mtHotelOrderJobDealVo.getMtHotelId(),
                    String.valueOf(mtHotelOrderJobDealVo.getGoodsId()),mtHotelOrderJobDealVo.getCheckinDate(),mtHotelOrderJobDealVo.getCheckoutDate(),mtHotelOrderJobDealVo.getRoomnum(),mtHotelOrderJobDealVo.getTotalPrice(),GsonUtils.GsonString(mtHotelOrderCheckVo));

            /*[JOBMT-CHECK] 订单将延迟处理 :2020-09-15 15:00:19  下单前校验未通过：{"code":3,"desc":"产品goodsId:51794353不可预订, goodsStatus:0","priceModels":[],"remainRoomNum":0}*/
        }
        if(!ObjectUtils.isEmpty(breakfastErrMsg)){
            //校验失败，修改pool表，将订单延迟处理(下单前校验未通过 不创建美团订单)
            SendUtils.dingMsgNotLog("[JOBMT-CHECK] 订单将延迟处理 ",DateUtil.getCurrTime()+" "+breakfastErrMsg+" 订单号="+swOrderId+tjMsg, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);
            updateToDelayOrderPool(DateUtil.getCurrTime()+errorMsg+" 订单号="+swOrderId,swPoolId,swOrderId,2);
            //早餐问题，保存延时订单日志
            saveDelayLog(swOrderId,MtGoodsEnums.DelayParentStatus.BREAKFAST.getCode(),MtGoodsEnums.DelayParentStatus.BREAKFAST.getMsg(),MtGoodsEnums.DelayStatus.BREAKFAST_OTHER.getCode(),MtGoodsEnums.DelayStatus.BREAKFAST_OTHER.getMsg(),
                    mtHotelOrderJobDealVo.getMtHotelId(),
                    String.valueOf(mtHotelOrderJobDealVo.getGoodsId()),mtHotelOrderJobDealVo.getCheckinDate(),mtHotelOrderJobDealVo.getCheckoutDate(),mtHotelOrderJobDealVo.getRoomnum(),mtHotelOrderJobDealVo.getTotalPrice(),breakfastErrMsg);
            return new Result<>(breakfastErrMsg,CommonConstants.SUCCESS);//延迟处理，返回给调用方success
        }
        if(!ObjectUtils.isEmpty(errorMsg)){
            boolean toPoolDealy;
            if(isCheckPriceDaysOrderToSplit){
                //下单前校验失败 判断为亏损失败，当前为连住订单，尝试拆单下单
                if(null == redisService.get("booking_to_split_close")){
                    ///一开始进入拆单--》将pool表订单改为人工关注拆单状态42（该状态区别于40人工处理单和2延时单）-》》  主单一开始状态也为42 人工处理拆单状态
                    Result rs = updateToDelayOrderPool(DateUtil.getCurrTime()+errorMsg+" 订单号="+swOrderId,swPoolId,swOrderId,42);
                    if(rs.getCode()!=CommonConstants.SUCCESS){
                        SendUtils.dingMsgNotLog("[JOBMT-CHECK] 携程订单状态改为人工关注拆单(42),但携程接口返回失败,技术人员请核实！",DateUtil.getCurrTime()+" "+errorMsg+" 订单号="+swOrderId+" 携程接口返回："+GsonUtils.GsonString(rs), MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);
                    }
                    //需创建子单（拆单）数据，当前pool表订单改为42 连住订单状态人工处理，系统不做操作延时单
                    SendUtils.dingMsgNotLog("[JOBMT-CHECK]。。新订单为连住订单，超亏损上限。。。。。。。。。。。。当前程序将进行拆单分析。。。。。。。。。。。。 ",DateUtil.getCurrTime()+" "+errorMsg+" 订单号="+swOrderId, MessageEnums.genre.ORDER_NOTICY.getCode(),restTemplate);
                    Boolean splitIsManmadeToBooking = false;
                    if(splitIsManmadeNotCheckPrice(sysStatus)){
                        splitIsManmadeToBooking = true;
                    }
                    Result splitOrderResult = mtHotelOrderDealSplitService.bookingPaySplitOrder(splitIsManmadeToBooking,mtHotelOrderJobDealVo,mtHotelOrderCheckVo,GsonUtils.GsonString(errorMsgResult),swOrderId,mtHotelId,goodsId,swPoolId,checkinDate,checkoutDate);
                    if(splitOrderResult.getCode()!=CommonConstants.SUCCESS){
                        SendUtils.dingMsgNotLog("[JOBMT-SPLIT-ERROR] 程序判断为拆单条件不足停止拆单，订单将延时处理 ",DateUtil.getCurrTime()+" 订单号="+swOrderId+tjMsg, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);
                        //超亏损，拆单不足1，保存延时订单日志
                        saveDelayLog(swOrderId,
                                MtGoodsEnums.DelayParentStatus.CHECK.getCode(),MtGoodsEnums.DelayParentStatus.CHECK.getMsg(),MtGoodsEnums.DelayStatus.CHECK_MAX.getCode(),MtGoodsEnums.DelayStatus.CHECK_MAX.getMsg(),
                                mtHotelId,
                                String.valueOf(goodsId),checkinDate,checkoutDate,roomnum,swTotalPrice,"[试单失败]拆单条件不足1");
                        toPoolDealy = false;//订单被改为42了
                        errorMsg = splitOrderResult.getMsg().toString();
                    }else{
                        //等待异步通知--》在异步通知那边判断为最后一笔子单完成预定，推送该钉钉消息
                        /*SendUtils.dingMsgNotLog("[SPLIT-SUCCESS] 所有子单成功采购完成 ^ 0 ^ ^ 0 ^  ",DateUtil.getCurrTime()+
                                " 连住主订单号："+swOrderId+" 入住离店时间："+checkinDate+"+"+checkoutDate+" 房间数："+masterRoomnum,MessageEnums.genre.ORDER_NOTICY.getCode(),restTemplate);*/
                        return new Result<>("连住订单，程序拆单成功，等待美团异步通知",CommonConstants.SUCCESS);//返回给调用方success
                    }
                }else{
                    SendUtils.dingMsgNotLog("[JOBMT-CHECK] 拆单通道已关闭，请人工关注该连住订单 ",DateUtil.getCurrTime()+" "+errorMsg+" 订单号="+swOrderId+tjMsg, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);
                    //超亏损，拆单不足2，保存延时订单日志
                    saveDelayLog(swOrderId,
                            MtGoodsEnums.DelayParentStatus.CHECK.getCode(),MtGoodsEnums.DelayParentStatus.CHECK.getMsg(),MtGoodsEnums.DelayStatus.CHECK_MAX.getCode(),MtGoodsEnums.DelayStatus.CHECK_MAX.getMsg()
                            ,mtHotelId,
                            String.valueOf(goodsId),checkinDate,checkoutDate,roomnum,swTotalPrice,"[试单失败]拆单条件不足2");
                    toPoolDealy = true;
                }
            }else{
                //下单前校验失败 判断code后试单失败，保存延时订单日志
                String remark = null;
                Integer thisChildCode = MtGoodsEnums.DelayStatus.contains(errorMsg);
                if(ObjectUtils.isEmpty(thisChildCode)){
                    thisChildCode = MtGoodsEnums.DelayStatus.CHECK_OTHER.code();
                    remark = GsonUtils.GsonString(mtHotelOrderCheckVo);
                }
                //超亏损，拆单不足2，保存延时订单日志
                saveDelayLog(swOrderId,
                        MtGoodsEnums.DelayParentStatus.CHECK.getCode(),MtGoodsEnums.DelayParentStatus.CHECK.getMsg(),thisChildCode,MtGoodsEnums.DelayStatus.getMsg(thisChildCode)//[试单失败]code返回不成功
                        ,mtHotelId,
                        String.valueOf(goodsId),checkinDate,checkoutDate,roomnum,swTotalPrice,remark);
                toPoolDealy = true;
            }
            if(toPoolDealy){
                //校验失败，修改pool表，将订单延迟处理(下单前校验未通过 不创建美团订单)
                SendUtils.dingMsgNotLog("[JOBMT-CHECK] 订单将延迟处理 ",DateUtil.getCurrTime()+" "+errorMsg+" 订单号="+swOrderId+tjMsg, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);

                updateToDelayOrderPool(DateUtil.getCurrTime()+errorMsg+" 订单号="+swOrderId,swPoolId,swOrderId,2);


                //异常延时单：同步查询日历价格和日历房态
                Result thisPriApi = mtHotelGoodsService.saveGetMtHotelGoodsPrice(Long.valueOf(goodsId),checkinDate,checkoutDate);
                log.info("新订单延迟PR:"+GsonUtils.GsonString(thisPriApi));
                String thisStatJson = null;
                Integer goodsType = MtHotelEnums.goodsTypeEnum.oneDay.getCode();
                Result result = mtHotelGoodsService.getMtHotelGoodsStatus(Long.valueOf(mtHotelId), checkinDate, checkoutDate, goodsType, null);
                if (result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())) {
                    try {
                        MtHotelGoodsStatusVo mtHotelGoodsStatusVo = (MtHotelGoodsStatusVo) result.getData();
                        if (null != mtHotelGoodsStatusVo) {
                            List<MtHotelGoodsStatusDetailVo> goodsStatuses = mtHotelGoodsStatusVo.getGoodsStatuses();
                            if (null != goodsStatuses && goodsStatuses.size() > 0) {
                                //Map<Integer, List<MtHotelGoodsStatusDetailStateVo>> map = new HashMap<>();
                                for (MtHotelGoodsStatusDetailVo vo : goodsStatuses) {
                                    if(String.valueOf(vo.getGoodsId()).equals(String.valueOf(goodsId))){
                                        thisStatJson = GsonUtils.GsonString(vo);
                                        break;
                                    }
                                }
                            }
                        } else {
                        }
                    }catch (Exception e){
                        log.error("新订单：延时单：查询房态日历异常："+e.getMessage());
                        e.printStackTrace();
                    }
                }
                log.info("新订单延迟ST:"+GsonUtils.GsonString(result));
                if(ObjectUtils.isEmpty(thisStatJson)){
                    thisStatJson = GsonUtils.GsonString(result);
                }
                SendUtils.dingMsgNotLog("[JOBMT-CHECK] 延时单，当前立即同步查询日历价格和房态 ",DateUtil.getCurrTime()+"  价格："+GsonUtils.GsonString(thisPriApi)+"   房态："+GsonUtils.GsonString(thisStatJson)+"  订单号:"+swOrderId+tjMsg, MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);

            }
            return new Result<>(errorMsg,CommonConstants.SUCCESS);//延迟处理，返回给调用方success
        }

        //3、校验通过，可下单美团
        Result mtDisOrderIdIndexResult = getMtDisOrderIdIndex(swOrderId,mtHotelId,goodsId,swPoolId);
        if(mtDisOrderIdIndexResult.getCode()==CommonConstants.SUCCESS){
            String mtDisOrderId_index  = (String)mtDisOrderIdIndexResult.getData();
            if(isLoss){
                try{
                    //查询价格日历接口看是否接口和下单前校验接口返回的新价格是同步一样的
                    Result thisPriApi = mtHotelGoodsService.saveGetMtHotelGoodsPrice(Long.valueOf(goodsId),checkinDate,checkoutDate);
                    SendUtils.dingMsgNotLog("新订单 发生允许范围内亏损 ",DateUtil.getCurrTime()+" 订单号："+swOrderId+" 携程订单价格："+isLossMsg.split("_")[1]+" 美团采购结算价："+isLossMsg.split("_")[2]+" 同步查询价格日历："+GsonUtils.GsonString(thisPriApi),MessageEnums.genre.ORDER_LOSS.getCode(),restTemplate);
                }catch (Exception e){
                    log.error("亏损单发送钉钉异常:"+e.getMessage());
                    e.printStackTrace();
                }
            }
            return booking(tjMsg,mtHotelOrderCheckVo,mtHotelOrderJobDealVo,mtDisOrderId_index);
        }else{
            return mtDisOrderIdIndexResult;
        }
    }

    /**
     * 早餐校验和  代码从2小时定时器那边copy过来
     * @param thisMtHotelId
     * @param thisGoodsId
     * @return
     */
    private Result checkThisGoodsBreakfast(String swOrderId,String thisMtHotelId,String thisGoodsId) {
        log.info("新订单进入查询早餐信息swOrderId={},thisMtHotelId={},thisGoodsId={}",swOrderId,thisMtHotelId,thisGoodsId);
        if(null != redisService.get("booking_checkThisGoodsBreakfast_close")){
            return new Result();
        }
        List<Long> hotelList = new ArrayList<>();
        hotelList.add(Long.valueOf(thisMtHotelId));
        Result breakres = getTendHotelGoodsInfoForBooking(hotelList);
        MtHotelGoodsVo mtHotelGoodsVo = null;
        if(null != breakres.getData()){
            mtHotelGoodsVo = GsonUtils.objToBean(breakres.getData(),MtHotelGoodsVo.class);
        }
        String failBreakfastErrMsg = "";
        try {
            List<MtHotelGoodsBreakfastVo> thisNewGoodsBreakfastVos = null;
            if(null != mtHotelGoodsVo && mtHotelGoodsVo.getHotelGoods().size()>0){
                for (MtHotelGoodsChildInfoVo oneHotel:mtHotelGoodsVo.getHotelGoods()){
                    List<MtHotelGoodsBaseInfoVo> oneHotelgoodsData = oneHotel.getGoods();
                    if(null != oneHotelgoodsData && oneHotelgoodsData.size()>0){
                        for (MtHotelGoodsBaseInfoVo thisHotelOneGoodsInfo:oneHotelgoodsData){
                            if(thisGoodsId.equals(thisHotelOneGoodsInfo.getGoodsId())){
                                thisNewGoodsBreakfastVos = thisHotelOneGoodsInfo.getBreakFast();
                            }
                        }
                    }
                }

            }else{
                log.error("新订单未查询到产品信息swOrderId={},thisMtHotelId={},thisGoodsId={}",swOrderId,thisMtHotelId,thisGoodsId);
            }
            /**
             * 早餐类型：
             * 0 不含早餐
             * 1 含有breakfastNum份免费早餐
             * 2 收费早餐
             */
            if(null != thisNewGoodsBreakfastVos && thisNewGoodsBreakfastVos.size()>0){
                /**
                 * 早餐类型：
                 * 0 不含早餐
                 * 1 含有breakfastNum份免费早餐
                 * 2 收费早餐
                 */
                MtHotelGoodsBreakfastVo todayBreakfast = new MtHotelGoodsBreakfastVo();
                if(thisNewGoodsBreakfastVos.size()>1){
                    log.info("早餐信息数量大于1，goodsId={},thisNewGoodsBreakfastVos={}",thisGoodsId,GsonUtils.GsonString(thisNewGoodsBreakfastVos));
                    for (int i = 0; i < thisNewGoodsBreakfastVos.size(); i++) {
                        MtHotelGoodsBreakfastVo b = thisNewGoodsBreakfastVos.get(i);
                        if(b.getInStartDate()!=0){
                            Integer s = b.getInStartDate();
                            Integer e = b.getInEndDate();
                            String end = null;
                            String start = null;
                            try {
                                start = DateUtil.parseStrYYYYMMDD(String.valueOf(s));
                                end = DateUtil.parseStrYYYYMMDD(String.valueOf(e));
                            } catch (ParseException e1) {
                                e1.printStackTrace();
                            }
                            Map<String,String> days = DateUtil.getTwoDaysDay(String.valueOf(start),String.valueOf(end));
                            if(null != days.get(DateUtil.getCurrTimeYmd("yyyy-MM-dd"))){
                                log.info("早餐信息数量大于1，goodsId={},当前指定日期早餐规则，今日符合 start={}，end={}",thisGoodsId,start,end);
                                //‘今天’属于指定时间的早餐
                                todayBreakfast = b;
                            }else{
                                //‘今天’不属于指定时间的早餐，则一定是属于另一个 inStartDate = 0 这一组早餐规则
                                if(i==0){
                                    todayBreakfast = thisNewGoodsBreakfastVos.get(1);
                                }else{
                                    todayBreakfast = thisNewGoodsBreakfastVos.get(0);
                                }
                                log.info("早餐信息数量大于1，goodsId={},当前指定日期早餐规则，今日不符合选择0选项 todayBreakfast={}",thisGoodsId,GsonUtils.GsonString(todayBreakfast));
                            }
                            break;
                        }
                    }
                }else{
                    todayBreakfast = thisNewGoodsBreakfastVos.get(0);
                }
                Integer thisNewGoodsNewBfType = todayBreakfast.getBreakfastType();
                Integer thisNewGoodsNewBfNum = todayBreakfast.getBreakfastNum();

                Integer hasBreakfastValueIsNum = (Integer)redisService.get(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+thisMtHotelId+"_"+thisGoodsId+"_1");//有存在值 说明是上架的产品 key=1有早餐  value=数量
                if(null != hasBreakfastValueIsNum){//如果当前产品是推送的有早餐，则进行校验,当前产品早餐是否变为  1、无早   2、早餐数量是否变更
                    if(1 != thisNewGoodsNewBfType){
                        //SendUtils.dingMsgNotLog("[FAIL-BREAKFAST]","该产品早餐从有到无，列入失效产品队列，等待消费处理，酒店id="+thisMtHotelId+" 产品id="+thisGoodsId,MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                        log.info("新订单校验存在早餐信息变化产品早餐从免费变为无早餐或者收费早餐 hotelid={},thisNewGoodsBreakfastVos={}",thisMtHotelId,GsonUtils.GsonString(thisNewGoodsBreakfastVos));
                        //早餐从免费变为 无早餐或者收费早餐，加入失效产品队列--》2020-11-24 携程早餐接口 单无双早都不给设置，相当于无效接口，后期不推送早餐修改。
                        MtHotelGoodsUpDownLog mtHotelGoodsUpDownLog = new MtHotelGoodsUpDownLog();
                        mtHotelGoodsUpDownLog.setId(StringUtil.getUUID());
                        mtHotelGoodsUpDownLog.setMtHotelId(thisMtHotelId);
                        mtHotelGoodsUpDownLog.setMtGoodsId(thisGoodsId);
                        mtHotelGoodsUpDownLog.setMtRoomId(null);
                        mtHotelGoodsUpDownLog.setRemark("new="+thisNewGoodsNewBfType);
                        mtHotelGoodsUpDownLog.setCreateTime(new Date());
                        mtHotelGoodsUpDownLog.setSource("56");
                        mtHotelGoodsUpDownLog.setType("0");
                        mtHotelGoodsUpDownLogMapper.insert(mtHotelGoodsUpDownLog);
                        failBreakfastErrMsg = "新订单校验，早餐信息变化产品早餐从免费变为无早，请核实";
                    }else if(thisNewGoodsNewBfNum<hasBreakfastValueIsNum){
                        log.info("新订单校验存在早餐信息变化产品该产品早餐数量小于上架时早餐数量 hotelid={},hasBreakfastValueIsNum={}，thisNewGoodsNewBfNum={}",thisMtHotelId,hasBreakfastValueIsNum,thisNewGoodsNewBfNum);
                        //早餐从免费变为 无早餐或者收费早餐，加入失效产品队列--》2020-11-24 携程早餐接口 单无双早都不给设置，相当于无效接口，后期不推送早餐修改。
                        MtHotelGoodsUpDownLog mtHotelGoodsUpDownLog = new MtHotelGoodsUpDownLog();
                        mtHotelGoodsUpDownLog.setId(StringUtil.getUUID());
                        mtHotelGoodsUpDownLog.setMtHotelId(thisMtHotelId);
                        mtHotelGoodsUpDownLog.setMtGoodsId(thisGoodsId);
                        mtHotelGoodsUpDownLog.setMtRoomId(null);
                        mtHotelGoodsUpDownLog.setRemark("old="+hasBreakfastValueIsNum+",new="+thisNewGoodsNewBfNum);
                        mtHotelGoodsUpDownLog.setCreateTime(new Date());
                        mtHotelGoodsUpDownLog.setSource("57");
                        mtHotelGoodsUpDownLog.setType("0");
                        mtHotelGoodsUpDownLogMapper.insert(mtHotelGoodsUpDownLog);
                        failBreakfastErrMsg = "新订单校验，产品早餐数量小于上架时早餐数量，请核实：最新数量="+thisNewGoodsNewBfNum+"，上架数量="+hasBreakfastValueIsNum;
                    }
                }
            }else{
                SendUtils.dingMsgNotLog("[ORDER-BREAKFAST]",DateUtil.getCurrTime()+" 异常关注，新订单未查询到产品早餐，酒店id="+thisMtHotelId+" 产品id="+thisGoodsId,MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                log.error("新订单未查询到产品早餐thisMtHotelId={},thisGoodsId={}",thisMtHotelId,thisGoodsId);
            }
        }catch (Exception e){
            log.error("checkThisGoodsBreakfast 新订单校验早餐异常："+e.getMessage());
            e.printStackTrace();
        }
        if(!ObjectUtils.isEmpty(failBreakfastErrMsg)){
            log.info("该新订单早餐信息异常swOrderId={},date={}",swOrderId,GsonUtils.GsonString(breakres));
            return new Result(failBreakfastErrMsg,CommonConstants.REQUEST_ERROR);
        }else{
            return new Result();
        }
    }

    public Result<Object> getTendHotelGoodsInfoForBooking(List<Long> hotelList) {
        Result<Object> apiResult = null;
        try{
            Integer days = mtHotelGoodsService.getDaysCommonBaseSetForVip();
            MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo = new MtHotelGoodsSpecParamVo();
            mtHotelGoodsSpecParamVo.setGoodsType(MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            mtHotelGoodsSpecParamVo.setCheckinDate(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            mtHotelGoodsSpecParamVo.setCheckoutDate(DateUtil.formatDate(DateUtil.addDay(new Date(),days),"yyyy-MM-dd"));
            apiResult = mtHotelGoodsService.getMtHotelGoods(null,hotelList,mtHotelGoodsSpecParamVo.getCheckinDate(),mtHotelGoodsSpecParamVo.getCheckoutDate(),mtHotelGoodsSpecParamVo.getGoodsType());
            if(apiResult.getCode()==CommonConstants.SUCCESS){
                return new Result<>(apiResult.getData());
            }
        }catch (Exception e){
            log.error("findMtGoodsCheckUpDown getMtGoodsByHotelIdForJob 异常："+e.getMessage()+",apiResult="+GsonUtils.GsonString(apiResult));
            apiResult = new Result<>("error:"+e.getMessage());
            e.printStackTrace();
        }
        return apiResult;
    }

    private Result paramsBooking(MtHotelOrderCheckVo mtHotelOrderCheckVo,MtHotelOrderJobDealVo mtHotelOrderJobDealVo,String mtDisOrderId_index){
        //参数
        String mtHotelId = mtHotelOrderJobDealVo.getMtHotelId();//美团酒店id
        Integer goodsId = mtHotelOrderJobDealVo.getGoodsId();//美团产品id
        String checkinDate = mtHotelOrderJobDealVo.getCheckinDate();//日期格式 yyyy-MM-dd
        String checkoutDate = mtHotelOrderJobDealVo.getCheckoutDate();
        Integer roomnum = mtHotelOrderJobDealVo.getRoomnum();
        String swPoolId = mtHotelOrderJobDealVo.getSwPoolId();
        String swOrderId = mtHotelOrderJobDealVo.getSwOrderId();
        Integer swTotalPrice = mtHotelOrderJobDealVo.getTotalPrice();

        //校验通过，向美团下单,再次更新缓存标识失效时间
        String key = MeituanConstants.REDIS_KEY_HEAD_MT_ORDER_JOB_ING_VALUE_ORDER_ID+swOrderId;
        redisTemplate.opsForValue().set(key,"1",6, TimeUnit.SECONDS);

        //美团下单前校验返回最新价格 priceModels
        List<MtHotelOrderCheckPricesVo> priceModels = mtHotelOrderCheckVo.getPriceModels();
        int mtShowSaleTotalPrice = 0;//美团订单市场价总价
        int subPrice = 0;//美团分销商佣金
        for (MtHotelOrderCheckPricesVo priceModel : priceModels) {
            //美团采购订单总价 * 房间数
            mtShowSaleTotalPrice = mtShowSaleTotalPrice + (priceModel.getSalePrice() * roomnum);
            //每间佣金 * 房间数
            subPrice = subPrice + (priceModel.getSubPrice() * roomnum);
        }
        Integer costTotalPrice = BigDecimal.valueOf(mtShowSaleTotalPrice).subtract(BigDecimal.valueOf(subPrice)).intValue();//结算采购成本总价=总价减去分销商佣金

        MtHotelOrderBookingParamVo mtHotelOrderBookingParamVo = new MtHotelOrderBookingParamVo();
        mtHotelOrderBookingParamVo.setDistributorOrderId(mtDisOrderId_index);
        mtHotelOrderBookingParamVo.setHotelId(mtHotelId);
        mtHotelOrderBookingParamVo.setGoodsId(String.valueOf(goodsId));
        mtHotelOrderBookingParamVo.setPersonNames(mtHotelOrderJobDealVo.getPersonNames());
        mtHotelOrderBookingParamVo.setContactName(mtHotelOrderJobDealVo.getContactName());
        //todo 携程订单联系人电话暂无,使用400号码
        mtHotelOrderBookingParamVo.setContactPhone(StringUtil.getQueuePhone(redisTemplate));
        mtHotelOrderBookingParamVo.setMtHotelOrderCheckVo(mtHotelOrderCheckVo);
        mtHotelOrderBookingParamVo.setCheckinDate(checkinDate);
        mtHotelOrderBookingParamVo.setCheckoutDate(checkoutDate);
        mtHotelOrderBookingParamVo.setRoomNum(roomnum);
        mtHotelOrderBookingParamVo.setTotalPrice(mtShowSaleTotalPrice);
        mtHotelOrderBookingParamVo.setSettlePrice(costTotalPrice);
        mtHotelOrderBookingParamVo.setMtHotelOrderCheckVo(mtHotelOrderCheckVo);

        log.info("调用下单api booking请求参数={}", JSON.toJSONString(mtHotelOrderBookingParamVo));
        Result bookingResult = mtHotelOrderService.orderBookingApi(mtHotelOrderBookingParamVo,swTotalPrice);
        log.info("调用下单api返回={}", JSON.toJSONString(bookingResult));
        return bookingResult;
    }
    /**
     * 1.1 下单美团（通过校验）
     * @param mtHotelOrderCheckVo
     * @param mtHotelOrderJobDealVo
     * @param mtDisOrderId_index
     * @return
     */
    public Result booking(String tjMsg,MtHotelOrderCheckVo mtHotelOrderCheckVo,MtHotelOrderJobDealVo mtHotelOrderJobDealVo,String mtDisOrderId_index){
        String swPoolId = mtHotelOrderJobDealVo.getSwPoolId();
        String swOrderId = mtHotelOrderJobDealVo.getSwOrderId();
        Result bookingResult = this.paramsBooking(mtHotelOrderCheckVo,mtHotelOrderJobDealVo,mtDisOrderId_index);
        Object orderData = bookingResult.getData();
        MtHotelOrderBookingVo mtHotelOrderBookingVo = JacksonUtil.objToBean(orderData, MtHotelOrderBookingVo.class);
        if (bookingResult.getCode() == CommonConstants.SUCCESS && null != mtHotelOrderBookingVo) {
            if(null != bookingResult.getMsg() && bookingResult.getMsg().toString().contains("重复订单")){
                log.info("booking orderBookingApi 重复订单号,当前次定时器不操作:{},{}",mtDisOrderId_index, JSON.toJSONString(mtHotelOrderJobDealVo));
                return new Result<>(DateUtil.getCurrTime()+" 重复订单号下单失败："+mtDisOrderId_index,CommonConstants.REQUEST_ERROR);
            }
            Integer code = mtHotelOrderBookingVo.getCode();
            log.info("Switch Hotel Order From Meituan Job  >>>>>>>> 调用美团预约下单，接口返回: {}", JSON.toJSONString(bookingResult));
            /***
             * 	下单结果码：
             * 0 下单成功
             * 1 系统繁忙，请稍后重试
             * 2 产品已变价
             * 3 重复订单, 对应下单失败
             * 4 产品已售完，扣减库存失败
             * 5 账户扣款失败
             * 10 产品被拉黑, 不允许购买
             * 11 该产品如选择预计到店时间在 XXXX 之后的，需支付相应担保金，第一期暂不支持下担保产品的订单!
             * 20 其它
             */
            if(code ==0){
                //预下单成功，等待异步通知>>>>>>>>>>美团预下单接口中已发送钉钉消息推送  当前不再推送
                updateOrderPoolBookingSuccess(mtHotelOrderCheckVo, mtHotelOrderJobDealVo,mtDisOrderId_index,mtHotelOrderBookingVo.getMtOrderId());

                if(null != redisService.get("sw_simi_min_check_close")){
                    meituanNewOrderCheckSimiTask.executeCheckSimi(mtHotelOrderJobDealVo);
                }

            }else{
                //方法内部延时单已发送dingding

                String remark = null;
                Integer thisChildCode = MtGoodsEnums.DelayStatus.contains(mtHotelOrderBookingVo.getDesc());
                if(ObjectUtils.isEmpty(thisChildCode)){
                    thisChildCode = MtGoodsEnums.DelayStatus.BOOKING_OTHER.code();
                    remark = GsonUtils.GsonString(mtHotelOrderBookingVo);
                }

                //预下单接口返回失败Code!=0，保存延时订单日志
                saveDelayLog(swOrderId,
                        MtGoodsEnums.DelayParentStatus.BOOKING.getCode(),MtGoodsEnums.DelayParentStatus.BOOKING.getMsg(),thisChildCode,MtGoodsEnums.DelayStatus.getMsg(thisChildCode),//[预下单失败]预下单接口返回失败Code!=0
                        mtHotelOrderJobDealVo.getMtHotelId(),
                        String.valueOf(mtHotelOrderJobDealVo.getGoodsId()),mtHotelOrderJobDealVo.getCheckinDate(),mtHotelOrderJobDealVo.getCheckoutDate(),mtHotelOrderJobDealVo.getRoomnum(),mtHotelOrderJobDealVo.getTotalPrice(),remark);

                log.info("voCode!=0下单失败："+ JSON.toJSONString(mtHotelOrderCheckVo));
                updateToDelayOrderPool(DateUtil.getCurrTime()+" 预下单提交失败1 改为延时单"+" ，订单号="+swOrderId,swPoolId,swOrderId,2);
            }
        }else{
            SendUtils.dingMsgNotLog("[JOBMT-BOOKING-2] 订单将延迟处理 ",DateUtil.getCurrTime()+" 预下单提交失败："+ JSON.toJSONString(bookingResult)+" 订单号="+swOrderId+tjMsg, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);

            //预下单接口返回失败，保存延时订单日志
            saveDelayLog(swOrderId,
                    MtGoodsEnums.DelayParentStatus.BOOKING.getCode(),MtGoodsEnums.DelayParentStatus.BOOKING.getMsg(),MtGoodsEnums.DelayStatus.BOOKING_OTHER.getCode(),MtGoodsEnums.DelayStatus.BOOKING_OTHER.getMsg(),//[预下单失败]预下单接口失败
                    mtHotelOrderJobDealVo.getMtHotelId(),
                    String.valueOf(mtHotelOrderJobDealVo.getGoodsId()),mtHotelOrderJobDealVo.getCheckinDate(),mtHotelOrderJobDealVo.getCheckoutDate(),mtHotelOrderJobDealVo.getRoomnum(),mtHotelOrderJobDealVo.getTotalPrice(),GsonUtils.GsonString(mtHotelOrderBookingVo));

            updateToDelayOrderPool(DateUtil.getCurrTime()+" 预下单提交失败："+ JSON.toJSONString(bookingResult)+" 订单号="+swOrderId,swPoolId,swOrderId,2);
            return new Result<>(DateUtil.getCurrTime()+" 预下单提交失败："+ JSON.toJSONString(bookingResult),CommonConstants.SUCCESS);//改为延迟单，返回给调用方success
        }

        return new Result(JSON.toJSONString(bookingResult),"success");
    }

    /**
     * 1.1.1 更新携程pool订单为美团下单成功
     * @param mtHotelOrderCheckVo
     * @param mtHotelOrderJobDealVo
     * @param mtDisId_index
     * @param mtOrderId
     */
    @Override
    public void updateOrderPoolBookingSuccess(MtHotelOrderCheckVo mtHotelOrderCheckVo, MtHotelOrderJobDealVo mtHotelOrderJobDealVo,String mtDisId_index,String mtOrderId) {
        //参数
        String swPoolId = mtHotelOrderJobDealVo.getSwPoolId();
        String swOrderId = mtHotelOrderJobDealVo.getSwOrderId();

        //更新携程订单实时状态池接口
        String updateOrderResultUrl = CommonUrlConstants.SWITCHS_HOST + UrlSwitchsEnums.switchOrderPool.POST_SWITCH_UPDATE_ORDER_RESULT.getValue();

        //请求参数
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("sysOrderState", 9);//系统状态 9  确认中(美团订单已提交预定)
        dataMap.put("mtOrderState", "20");//美团状态 20：已提交预定中
        dataMap.put("orderId", swOrderId);
        dataMap.put("remark",DateUtil.getCurrTime()+" 下单定时器预下单已提交，等待美团通知");
        dataMap.put("id", swPoolId);
        dataMap.put("mtDistributorOrderId", mtDisId_index);//disid_index 美团序号订单号
        dataMap.put("meituanOrderId", mtOrderId);//第三方美团平台订单号
        if(null != mtHotelOrderCheckVo) {
            dataMap.put("mtCode", mtHotelOrderCheckVo.getCode());
            dataMap.put("mtDesc", mtHotelOrderCheckVo.getDesc());
            dataMap.put("mtPriceModels", JacksonUtil.objectToJson(mtHotelOrderCheckVo.getPriceModels()));
            dataMap.put("mtRemainRoomNum", mtHotelOrderCheckVo.getRemainRoomNum());
        }
        String dataJson = JacksonUtil.objectToJson(dataMap);

        log.info("美团下单处理方法，updateOrderResult 修改订单pool信息 请求：{}",dataJson);
        Result response = RestTemplateUtils.post(updateOrderResultUrl,dataJson,restTemplate);
        log.info("美团下单处理方法，updateOrderResult 修改订单pool信息 响应：{}",JacksonUtil.objectToJson(response));
    }

    /**
     * 外部接口：校验订单价格公共方法
     * @return
     */
    @Override
    public Result checkPriceUpDownCommon(MtHotelOrderCheckParamVo mtHotelOrderParamVo) {
        log.info("checkPriceUpDownCommon 进入校验价格涨跌公共方法={}", JSON.toJSONString(mtHotelOrderParamVo));
        Integer swTotalPrice;
        Integer roomnum;
        MtHotelOrderCheckVo mtHotelOrderCheckVo = null;
        Result apiOrderCheck = mtHotelOrderService.orderCheckApi(mtHotelOrderParamVo);
        if(apiOrderCheck.getCode()==CommonConstants.SUCCESS){
            mtHotelOrderCheckVo = (MtHotelOrderCheckVo) apiOrderCheck.getData();
            roomnum = mtHotelOrderParamVo.getRoomNum();
            swTotalPrice = mtHotelOrderParamVo.getTotalPrice();
        }else{
            Result result = new Result();
            result.setMsg("公告校验请求下单前校验api返回失败");
            result.setCode(CommonConstants.REQUEST_ERROR);
            result.setData(mtHotelOrderCheckVo);
            return result;
        }

        return this.checkPriceUpDown(mtHotelOrderCheckVo,swTotalPrice,roomnum);
    }

    /**
     * 1.2 校验价格涨跌
     * @param swTotalPrice
     *
     * mtHotelOrderCheckVo 取字段做判断如果有调整需要看 split方法是否需要也做调整
     *
     * {"code":8,"desc":"下单卖价校验失败 - 产品id：638537167, 传入价格为：24780, 实际价格为：0","priceModels":[{"date":"2021-03-26","dayType":0,"salePrice":0,"subPrice":0,"subRatio":800}],"remainRoomNum":999}
     *
     * @return
     */
    @Override
    public Result checkPriceUpDown(MtHotelOrderCheckVo mtHotelOrderCheckVo,Integer swTotalPrice,Integer roomnum) {
        log.info("checkPriceUpDown 进入校验价格涨跌={},{},{}", JSON.toJSONString(mtHotelOrderCheckVo),swTotalPrice,roomnum);
        Boolean isLoss = false;//是否是允许范围内的亏损单，需要推送钉钉
        String isLossMsg = "";
        Integer checkCode = mtHotelOrderCheckVo.getCode();
        String errorMsg = "";
        if(0 == checkCode || 8 == checkCode){//校验成功 0  价格发送变化 8//接口返回code=0是校验通过，不代表价格没变化，要比较价格

            //Integer newMtTotalPrice = mtHotelOrderCheckVo.getPriceModels().stream().mapToInt(MtHotelOrderCheckPricesVo::getSalePrice).sum() * roomnum;//重新计算总价:美团返回的单价相加
            //Integer costTotalPrice = mtHotelOrderCheckVo.getPriceModels().stream().mapToInt(MtHotelOrderCheckPricesVo::getSubPrice).sum() * roomnum;//当前订单 成本总价 2020-09-15 qyy
            //美团下单前校验返回最新价格 priceModels
            //美团下单前校验返回最新价格 priceModels
            List<MtHotelOrderCheckPricesVo> priceModels = mtHotelOrderCheckVo.getPriceModels();
            int mtShowSaleTotalPrice = 0;//美团订单市场价总价
            int subPrice = 0;//美团分销商佣金
            for (MtHotelOrderCheckPricesVo priceModel : priceModels) {
                //美团采购订单总价 * 房间数
                mtShowSaleTotalPrice = mtShowSaleTotalPrice + (priceModel.getSalePrice() * roomnum);
                //每间佣金 * 房间数
                subPrice = subPrice + (priceModel.getSubPrice() * roomnum);
            }

            if(BigDecimal.valueOf(mtShowSaleTotalPrice).compareTo(new BigDecimal(0))<=0){
                errorMsg ="下单前校验返回最新价格异常："+ JSON.toJSONString(mtHotelOrderCheckVo)+" 订单总价"+swTotalPrice+" 订购房间数"+roomnum;
            }else{
                Integer costTotalPrice = BigDecimal.valueOf(mtShowSaleTotalPrice).subtract(BigDecimal.valueOf(subPrice)).intValue();//结算采购成本总价=美团订单价减去分销商佣金

                Map<String,Object> notEqCheckResult = notEqCheckPri(swTotalPrice,costTotalPrice,isLoss,isLossMsg,errorMsg,priceModels,mtHotelOrderCheckVo,roomnum);//传进去的参数会被赋值，返回后有用
                if(new BigDecimal((Integer) notEqCheckResult.get("code")).compareTo(new BigDecimal(99))==0){
                    return new Result(GsonUtils.GsonString(notEqCheckResult),99);
                }
                isLoss = (Boolean) notEqCheckResult.get("isLoss");
                isLossMsg = (String)notEqCheckResult.get("isLossMsg");
                errorMsg = (String)notEqCheckResult.get("errorMsg");
            }

        }else{
            //校验未通过，延迟订单
            errorMsg = " 下单前校验未通过："+ JSON.toJSONString(mtHotelOrderCheckVo)+" 订单总价"+swTotalPrice+" 订购房间数"+roomnum;
        }
        log.info("下单前校验vo再次校验价格结果errorMsg={}",errorMsg);
        if(ObjectUtils.isEmpty(errorMsg)){
            if(isLoss){
                return new Result(isLossMsg,CommonConstants.SUCCESS);//isLoss为了判断是否低于采购价，但是没有超过亏损上限
            }else{
                return new Result();
            }
        }else{
            return new Result<>(errorMsg,CommonConstants.REQUEST_ERROR);
        }

    }
    //传进去的参数会被赋值，返回后有用
    @Override
    public Map<String,Object> notEqCheckPri(Integer swTotalPrice, Integer costTotalPrice, Boolean isLoss, String isLossMsg, String errorMsg, List<MtHotelOrderCheckPricesVo> priceModels, MtHotelOrderCheckVo mtHotelOrderCheckVo,Integer roomnum) {
        Map<String,Object> returnMap = new HashMap<>();
        if(BigDecimal.valueOf(swTotalPrice).compareTo(BigDecimal.valueOf(costTotalPrice))==-1){
            //携程订单价格小于美团最新价格时   重新校验是否可接单
            isLoss = true;
            isLossMsg = "isLoss_"+swTotalPrice+"_"+costTotalPrice;
            log.info("新订单，美团最新采购价大于携程订单价，当前亏损单，swTotalPrice={},美团结算价costTotalPrice={}",swTotalPrice,costTotalPrice);
            Map queryMap = new HashMap();
            queryMap.put("head",CommonBaseConstants.PRICE_INCREASE);
            List<SysCommonBase> sysCommonBaseList = mtHotelOrderBookingMapper.queryCommonBaseByGroupHead(queryMap);
            log.info("校验价格涨跌checkPriceUpDown获取配置={}", JSON.toJSONString(sysCommonBaseList));
            if(null != sysCommonBaseList && sysCommonBaseList.size()>0
                    && !ObjectUtils.isEmpty(sysCommonBaseList.get(0).getPlatformValue())
                    && !ObjectUtils.isEmpty(sysCommonBaseList.get(0).getOpValue())){
                SysCommonBase sysCommonBase = sysCommonBaseList.get(0);
                Integer getPlatformValue = Integer.valueOf(sysCommonBaseList.get(0).getPlatformValue());

                BigDecimal newSwitchsTotolPriceMax = BigDecimal.valueOf(swTotalPrice);
                if(getPlatformValue == CommonBaseEnums.priceIncrease.CASH.getCode()){
                    newSwitchsTotolPriceMax = newSwitchsTotolPriceMax.add(new BigDecimal(sysCommonBase.getOpValue()));
                }else if(getPlatformValue == CommonBaseEnums.priceIncrease.PERCENT.getCode()){
                    newSwitchsTotolPriceMax = newSwitchsTotolPriceMax.multiply(new BigDecimal(sysCommonBase.getOpValue()));
                }else{
                    errorMsg = " 获取基础数据类型异常1："+ JSON.toJSONString(sysCommonBaseList);
                }

                if(ObjectUtils.isEmpty(errorMsg)){
                    Integer comparePrice = newSwitchsTotolPriceMax.compareTo(new BigDecimal(costTotalPrice));
                    if(comparePrice==-1){
                        Integer lossPrice = new BigDecimal(costTotalPrice).subtract(new BigDecimal(swTotalPrice)).intValue();
                        //加上基础设置价格后携程订单总价 小于 新采购价美团订单总价，当前不可接口，订单将延迟
                        Integer daysOrder = 0;//是否连住订单
                        if(getPlatformValue == CommonBaseEnums.priceIncrease.CASH.getCode()){
                            if(null != priceModels && priceModels.size()>1){
                                errorMsg = " 当前为连住订单！产品涨价超固定金额：总价"+swTotalPrice+" 房间数"+roomnum+"，亏损金额："+lossPrice+", 美团返回"+ JSON.toJSONString(mtHotelOrderCheckVo);
                                daysOrder = 1;
                            }else{
                                errorMsg = " 单住订单，产品涨价超固定金额：总价"+swTotalPrice+" 房间数"+roomnum+"，亏损金额："+lossPrice+",美团返回"+ JSON.toJSONString(mtHotelOrderCheckVo);
                            }

                        }else{
                            if(null != priceModels && priceModels.size()>1){
                                errorMsg = " 当前为连住订单！产品涨价超成本6%：总价"+swTotalPrice+" 房间数"+roomnum+"，亏损金额："+lossPrice+",美团返回"+ JSON.toJSONString(mtHotelOrderCheckVo);
                                daysOrder = 1;
                            }else{
                                errorMsg = " 单住订单，产品涨价超成本6%：总价"+swTotalPrice+" 房间数"+roomnum+"，亏损金额："+lossPrice+",美团返回"+ JSON.toJSONString(mtHotelOrderCheckVo);
                            }
                        }
                        if(null == redisService.get("booking_to_split_close")){
                            if(daysOrder==1){//连住订单有时候金额不对会判断为超亏损
                                //下单前校验通过code=0 或者 8  时候，判断为连住单，金额超限，当前做拆单操作：生成该订单的多笔单住订单，由人工去后台操作是否对多笔拆单进行下单
                                //return new Result<>(errorMsg,99);
                                returnMap.put("isLoss",isLoss);
                                returnMap.put("isLossMsg",isLossMsg);
                                returnMap.put("errorMsg",errorMsg);
                                returnMap.put("code",99);//返回code=99 当前为连住订单需要预先拆单订单数据生成 ---------》》》该返回有用
                                returnMap.put("msg","errorMsg");
                                return returnMap;
                            }
                        }
                    }else{
                        //比对价格通过，可下单
                    }
                }
            }else{
                //获取基础数据异常，将订单延迟
                errorMsg = " 获取基础数据类型异常2："+ JSON.toJSONString(sysCommonBaseList);
            }
        }
        returnMap.put("isLoss",isLoss);
        returnMap.put("isLossMsg",isLossMsg);
        returnMap.put("errorMsg",errorMsg);
        returnMap.put("code",200);
        returnMap.put("msg","success");
        return returnMap;//
    }



    /**
     * 1.4 设置锁，当前该订单执行，短时间锁失效6s
     * @param swOrderId
     * @return
     */
    private Result<Object> setLockOrderIdKey(String swOrderId) {
        /*String key = MeituanConstants.REDIS_KEY_HEAD_MT_ORDER_JOB_ING_VALUE_ORDER_ID+swOrderId;
        synchronized (key) {
            try {
                Thread.sleep(1);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
            //标识，，不让其他线程再进来处理当前订单
            String getRedis = (String)redisTemplate.opsForValue().get(key);
            if(!StringUtils.isEmpty(getRedis)){
                log.error("jobNewOrderBooking setLockOrderIdKey 已存在处理中订单，当前提交重复订单号 swOrderId="+swOrderId);
                return new Result<>("重复订单号，该订单号程序正在执行中swOrderId="+swOrderId,CommonConstants.REQUEST_ERROR);
            }
            redisTemplate.opsForValue().set(key,"1",6, TimeUnit.SECONDS);

        }
        return new Result<>();*/
        return checkRedisFpOrderId(swOrderId);
    }

    /**
     * 缓存锁，判断短时间内订单号重复
     * @Author qyy
     * @return
     */
    private Result checkRedisFpOrderId(String id) {
        Boolean check = false;
        Date date = DateUtil.addSecond(DateUtil.getCurrTime(),3);
        String timestamp = DateUtil.dateToStamp(DateUtil.formatDate(date,"yyyy-MM-dd HH:mm:ss"));
        String key = "fst_meituan_swmt_redis_order_apply_order_id_delay_again";
        if(null == redisService.get(key+id)){
            log.info("null fst_meituan_swmt_redis_order_apply_order_id_delay_again+id={}",key+id);
            try{
                boolean lock1 = redisLock.lock(key+id,timestamp);
                if(lock1){
                    log.info("null REDIS_ORDER_APPLY_FP_ORDER_ID+id 枷锁成功，更新缓存token ");
                    //枷锁成功，更新缓存token
                    redisService.setUnit(key+id,"1",1L, TimeUnit.MINUTES);
                    //解锁
                    redisLock.release(key+id,timestamp);
                }else{
                    //如果枷锁失败  很大可能是被其他线程枷锁，sleep后再获取redistoken
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                    log.error("fst_meituan_swmt_redis_order_apply_order_id_delay_again，加锁失败");
                    if(null != redisService.get(key+id)){
                        log.error("fst_meituan_swmt_redis_order_apply_order_id_delay_again，存在该订单号 1 id={}",key+id);
                        check = true;//存在该订单号
                    }
                }
            }catch (Exception e){
                log.info("fst_meituan_swmt_redis_order_apply_order_id_delay_again 异常catch :"+e.getMessage());
                e.printStackTrace();
            }
        }else{
            log.error("fst_meituan_swmt_redis_order_apply_order_id_delay_again，存在该订单号 2 id={}",key+id);
            check = true;//存在该订单号
        }
        if(check){
            return new Result("[MT1-REDIS-CHECK-ERROR]短时间内该订单号重复提交",CommonConstants.REQUEST_ERROR);
        }else{
            return new Result();
        }
    }

    /**
     * 1.5 构造美团订单序列号
     * @param swOrderId
     * @param mtHotelId
     * @param goodsId
     * @return
     */
    @Override
    public Result getMtDisOrderIdIndex(String swOrderId,String mtHotelId,Integer goodsId,String swPoolId) {
        //设置美团很好办订单号 = 携程订单号+序号
        String mtDisOrderId_index = swOrderId;
        List<MtHotelOrderBooking>  allThisSwNotVail = this.selectOneBySwOrderIdNotVail(swOrderId);
        if(null != allThisSwNotVail && allThisSwNotVail.size()>0){
            if(allThisSwNotVail.size()>8){
                log.info("当前该携程订单存在的失败单超出"+swOrderId);
                Result result =  new Result();
                result.setCode(CommonConstants.REQUEST_ERROR);
                result.setData(new MtHotelOrderBookingVo());
                result.setMsg("不再设置延时单，当前该携程订单存在的失败单达到="+allThisSwNotVail.size()+"单,将pool订单改为12人工处理单");
                //响应数据保存订单变化日志
                MtHotelOrderStateHistory stateHistory = new MtHotelOrderStateHistory();
                stateHistory.setMtDistributorOrderId(mtDisOrderId_index);
                stateHistory.setSwOrderId(swOrderId);
                stateHistory.setMtHotelId(mtHotelId);
                stateHistory.setMtGoodsId(String.valueOf(goodsId));
                stateHistory.setMtOrderId(null);
                stateHistory.setMethod(MtHotelEnums.apiMethodEnum.METHOD_HOTEL_ORDER_BOOKING.getMethod());
                stateHistory.setMethodName(MtHotelEnums.apiMethodEnum.METHOD_HOTEL_ORDER_BOOKING.getName());
                stateHistory.setStatusCode(null);
                stateHistory.setStatusDesc(null);
                stateHistory.setClassName("MtHotelOrderBookingVo");
                stateHistory.setClassJson("当前该携程订单存在的失败单超出="+allThisSwNotVail.size());
                //保存日志
                mtHotelOrderService.saveOrderStateHistory(stateHistory);

                SendUtils.dingMsgNotLog("[JOBMT-BOOKING-ERROR-STOP] 订单将更新状态为人工处理状态 ",DateUtil.getCurrTime()+ "该订单延时下单次数达到"+allThisSwNotVail.size()+"次，订单号="+swOrderId, MessageEnums.genre.DELAYED_ORDER.getCode(),restTemplate);

                mtHotelOrderService.requestUpdateStateOrderPool(DateUtil.getCurrTime()+"不再设置延时单，当前该携程订单存在的失败单达到="+allThisSwNotVail.size()+"单,将pool订单改为12人工处理单",
                        swOrderId,null,12,null,1,null,null);

                return result;
            }
            mtDisOrderId_index = mtDisOrderId_index +"00"+(allThisSwNotVail.size()+1);
        }else{
            mtDisOrderId_index = mtDisOrderId_index+"001";
        }
        return new Result<>(mtDisOrderId_index,"success");
    }

    /**
     * 1.6 判断当前下单请求，是否为很好办后台人工采购操作：是则无需校验价格高低直接采购
     * @param sysStatus
     * @return
     */
    private boolean isManmadeNotCheckPrice(Integer sysStatus) {
        if(null != sysStatus && sysStatus == 40){
            //40人工采购 无需做价格涨跌校验，直接下单
            return true;
        }
        return false;
    }

    /**
     * 拆单 判断当前下单请求，是否为很好办后台人工采购操作：是则无需校验价格高低直接采购
     * @param sysStatus
     * @return
     */
    private boolean splitIsManmadeNotCheckPrice(Integer sysStatus) {
        if(null != sysStatus && sysStatus == 62){
            //62 拆单可能出现超亏损，当为62 后台人工操作直采拆单时，无需做价格涨跌校验，直接下单
            return true;
        }
        return false;
    }

    /**
     * 1.6.1 根据订单序列号 判断是否已存在过订单
     * @param swOrderId
     * @return
     */
    public List<MtHotelOrderBooking> selectOneBySwOrderIdNotVail(String swOrderId) {
        Example example = new Example(MtHotelOrderBooking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("swOrderId",swOrderId);
        criteria.andEqualTo("state",1);
        List<MtHotelOrderBooking> mtHotelOrderBooking = mtHotelOrderBookingMapper.selectByExample(example);
        return mtHotelOrderBooking;
    }

    /**
     * 判断该携程id是否已提交过订单 state=0  则不可再提交，存在说明有订单在处理
     * @return
     */
    public List<MtHotelOrderBooking> selectOneBySwOrderIsVail(String swOrderId) {
        Example example = new Example(MtHotelOrderBooking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("swOrderId",swOrderId);
        criteria.andEqualTo("state",0);
        List<MtHotelOrderBooking> mtHotelOrderBooking = mtHotelOrderBookingMapper.selectByExample(example);
        if(null == mtHotelOrderBooking || mtHotelOrderBooking.size()==0){
            return null;
        }
        log.info("selectOneBySwOrderIsVail mtHotelOrderBooking ="+ JSON.toJSONString(mtHotelOrderBooking));
        return mtHotelOrderBooking;
    }

    /**
     * 1.3 更新携程pool订单为延迟单
     * @param isOrderRemark
     * @param swPoolId
     * @param swOrderId
     */
    private Result updateToDelayOrderPool(String isOrderRemark,String swPoolId,String swOrderId,Integer sysOrderState) {

        //更新携程订单实时状态池接口
        String updateOrderResultUrl = CommonUrlConstants.SWITCHS_HOST + UrlSwitchsEnums.switchOrderPool.POST_SWITCH_UPDATE_ORDER_RESULT.getValue();

        //请求参数
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("sysOrderState", sysOrderState);
        dataMap.put("isOrderRemark", isOrderRemark);
        dataMap.put("id", swPoolId);
        dataMap.put("orderId", swOrderId);
        dataMap.put("orderWaitTime", CommonConstants.SWITCH_ORDER_WAIT_TIME);
        dataMap.put("isOrder", 0);
        String dataJson = JacksonUtil.objectToJson(dataMap);
        Result orderResult = RestTemplateUtils.post(updateOrderResultUrl,dataJson,restTemplate);
        log.info("美团下单处理方法，updateToDealyOrderPool 修改订单pool信息 请求{}，响应：{}",dataJson,JacksonUtil.objectToJson(orderResult));
        return orderResult;
    }

    /**
     * 保存延时单日志
     * @param swOrderId
     * @param type
     * @param detail
     * @param mtHotelId
     * @param mtGoodsId
     * @param mtCheckinDate
     * @param mtCheckoutDate
     * @param mtRoomNum
     * @param swTotalPrice
     * @param remark
     */
    @Override
    public void saveDelayLog(String swOrderId,Integer parentType,String parentDetail,Integer type,String detail,String mtHotelId,
                             String mtGoodsId,String mtCheckinDate,String mtCheckoutDate,Integer mtRoomNum,Integer swTotalPrice,String remark){
        log.info("进入 saveDelayLog方法，swOrderId={}，type={},detail={},mtHotelId={},mtGoodsId={}," +
                        "mtCheckinDate={},mtCheckoutDate={},mtRoomNum={},swTotalPrice={},remark={}",swOrderId,type,detail,mtHotelId,mtGoodsId,
                mtCheckinDate,mtCheckoutDate,mtRoomNum,swTotalPrice,remark);
        try{
            MtHotelOrderDelayLog mtHotelOrderDelayLog = new MtHotelOrderDelayLog();
            mtHotelOrderDelayLog.setId(StringUtil.getUUID());
            mtHotelOrderDelayLog.setSwOrderId(swOrderId);
            mtHotelOrderDelayLog.setParentType(parentType);
            mtHotelOrderDelayLog.setParentDetail(parentDetail);
            mtHotelOrderDelayLog.setType(type);
            mtHotelOrderDelayLog.setDetail(detail);
            mtHotelOrderDelayLog.setMtHotelId(mtHotelId);
            mtHotelOrderDelayLog.setMtGoodsId(mtGoodsId);
            mtHotelOrderDelayLog.setMtCheckinDate(mtCheckinDate);
            mtHotelOrderDelayLog.setMtCheckoutDate(mtCheckoutDate);
            mtHotelOrderDelayLog.setMtRoomNum(mtRoomNum);
            mtHotelOrderDelayLog.setSwTotalPrice(swTotalPrice);
            mtHotelOrderDelayLog.setRemark(remark);
            mtHotelOrderDelayLog.setCreateTime(new Date());
            mtHotelOrderDelayLogMapper.insert(mtHotelOrderDelayLog);
        }catch (Exception e){
            log.info("saveDelayLog方法 异常：e:{}",e.getMessage());
            e.printStackTrace();
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/5/6
     * 获取延迟单列表
     */
    @Override
    public Result<Object> getDealOrderList(int pageCode, int pageSize, Map map) {
        PageHelper.startPage(pageCode,pageSize);
        List<MtHotelOrderDelayLog> mtHotelOrderDelayLogs=mtHotelOrderDelayLogMapper.getDealOrderList(map);
        PageInfo<MtHotelOrderDelayLog> pageInfo=new PageInfo<>(mtHotelOrderDelayLogs);
        return new Result<>(pageInfo);
    }
    /***
     * @Author: lmf
     * @Date: 2021/5/8
     * 获取延迟单数量
     */
    @Override
    public Result<Object> getDealOrderNum(Map map) {
        Integer num=mtHotelOrderDelayLogMapper.getDealOrderNum(map);
        return new Result<>(num);
    }



}
